﻿using System;
using System.Collections.Generic;
using System.Text;
using Vortex.Drawing;

namespace Vortex.SceneFramework {

	/// <summary>
	/// Simplest sprite-based element
	/// </summary>
	public class SpriteElement : ContentElement {
		private ISpriteSource _source;

		/// <summary>
		/// Gets or sets the sprite source.
		/// </summary>
		/// <value>The sprite source.</value>
		public ISpriteSource Source {
			get { return _source; }
			set {
				_source = value;
			}
		}

		/// <summary>
		/// Gets the bounding box of element in local coordinates.
		/// </summary>
		/// <value>The bounding box of element in local coordinates.</value>
		public override Rect BoundingBox {
			get {
				ISpriteSource source = Source;
				if (null != source) {
					Sprite sprite = source.ToSprite();
					return Rect.FromPoint(Vector2.Zero, sprite.Size);
				} else {
					return Rect.Empty;
				}
			}
		}

		/// <summary>
		/// Draws the sprite element content.
		/// </summary>
		/// <param name="canvas">The canvas to use for sprite element drawing.</param>
		protected override void Draw(Canvas2D canvas) {
			if (null != _source) {
				Sprite sprite = _source.ToSprite();

				//draw sprite with appropriate blending
				using (canvas <= Blending) {
					canvas.DrawSprite(Vector2.Zero, sprite, ContentColor);
				}
			}
		}
	}

}
